import os

from dotenv import load_dotenv

CONFIG_OPTIONS = ['FACE_NET_MODEL_PATH', 'FACE_NET_TORCH_HOME', 'FACE_DATA_PATH', 'ANTI_SPOOFING_TWO_STREAM_VIT_PATH']
CONFIGS = {}

BASE_DIR = os.path.abspath(os.path.dirname(__file__))

if os.path.exists(os.path.join(BASE_DIR, '.env')):
    print('Importing environment from .env file')
    load_dotenv(os.path.join(BASE_DIR, '.env'))
    for k in CONFIG_OPTIONS:
        CONFIGS[k] = os.getenv(k)


def get_config(key):
    return CONFIGS.get(key)


class Config:
    ENV = os.getenv("ENV")
    LOG_TO_STDOUT = (os.getenv("LOG_TO_STDOUT") == 'true')
    SQLALCHEMY_ECHO = (os.getenv("SQLALCHEMY_ECHO") == 'true')
    SQLALCHEMY_TRACK_MODIFICATIONS = (os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS") == 'true')
    FACE_NET_MODEL_PATH = os.getenv('FACE_NET_MODEL_PATH')
    FACE_NET_TORCH_HOME = os.getenv('TORCH_HOME')

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')

    @staticmethod
    def init_app(app):
        print('THIS APP IS IN DEBUG MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')


class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(BASE_DIR, 'app.sqlite')
    WTF_CSRF_ENABLED = False

    @staticmethod
    def init_app(app):
        print('THIS APP IS IN TESTING MODE. YOU SHOULD NOT SEE THIS IN PRODUCTION.')


class ProductionConfig(Config):
    DEBUG = False
    USE_RELOADER = False
    SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI')

    @staticmethod
    def init_app(app):
        pass


app_config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig,
}
